package zhongbo.java.air.dictionary.web.controller;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
import zhongbo.java.air.common.vo.PageVo;
import zhongbo.java.air.common.vo.ResultVo;
import zhongbo.java.air.dictionary.model.AirCraft;
import zhongbo.java.air.dictionary.service.IAirCraftService;
import zhongbo.java.air.dictionary.service.impl.AirCraftServiceImpl;

import java.util.List;

/**
 * 说明：
 * 飞机基础信息操作的相关接口
 *
 * @author 钟波dellNotebook
 * @since 2025年03月31日 星期一 08:30:28
 */
@Api(tags = "飞机相关接口")
//@ApiModel("/api/aircraft")
@RequestMapping("api/aircraft")
@RestController
public class AirCraftController {
    @Autowired
    private AirCraftServiceImpl airCraftService;

    @ApiOperation("增加飞机")
    @PostMapping("/addAirCraft")
    public ResultVo<String> addAirCraft(@RequestBody AirCraft airCraft) {
        String add = airCraftService.addAirCraft(airCraft);
        if (StrUtil.isNotBlank(add)) { // 如果不为空
            return ResultVo.ok(add);
        }
        return ResultVo.error("新增失败");
    }
    @ApiOperation("查询一个飞机")
    @GetMapping("/getAirCraft")
    public ResultVo<AirCraft> getAirCraftById(@RequestParam(defaultValue = "1") String airId) {
        AirCraft airCraft = airCraftService.getAirCraftById(airId);
        return ResultVo.ok(airCraft);
    }
    @ApiOperation("删除一个飞机")
    @DeleteMapping("/deleteAirCraft")
    public ResultVo<Integer> deleteAirCraft(@RequestParam(defaultValue = "1") String airId) {
        int delete = airCraftService.deleteAirCraft(airId);
        return ResultVo.ok(delete);
    }
    @ApiOperation("修改一个飞机")
    @PutMapping("/updateAirCraft")
    public ResultVo<AirCraft> updateAirCraft(@RequestBody AirCraft airCraft) {
        AirCraft updateAirCraft = airCraftService.updateAirCraft(airCraft);
        if (updateAirCraft != null) {
            return ResultVo.ok(updateAirCraft);
        }
        return ResultVo.error("修改失败");

    }
    @ApiOperation("查出所有的飞机")
    @GetMapping("/AllAirCraft")
    public ResultVo<List<AirCraft>> getAirCraftAll() {
        List<AirCraft> airCraftList = airCraftService.getAirCraftAll();
        return ResultVo.ok(airCraftList);
    }
    @ApiOperation("分页查询所有飞机")
    @GetMapping("/pageAirCraftAll")
    public ResultVo<PageVo<AirCraft>> page(@RequestParam(required = false) String aircraftType,
                                           @RequestParam(defaultValue = "1") Integer pageNumber,
                                           @RequestParam(defaultValue = "1") Integer pageSize) {
        PageVo<AirCraft> page = airCraftService.page(aircraftType,pageNumber,pageSize);
        return ResultVo.ok(page);
    }

}
